package busca.tesoros.uclm;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class InformacionActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
	private Intent i=null;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.informacion);
        
        View ButtonContinue = findViewById(R.id.button_continue);
        ButtonContinue.setOnClickListener((OnClickListener) this); 
        String [] vector=getIntent().getExtras().getStringArray("misionpista");
        
        //Realizar solo si la pista es correcta
        if(vector.length>2) //pasamos a la siguiente pista
        {
	        String [] vectorCopia=new String[vector.length-1];
	        
		        for(int j=0; j<vectorCopia.length; j++)
		        {
		        	vectorCopia[j]=vector[j+1];
		        }
	        i = new Intent(this, PistaActivity.class);
	        i.putExtra("misionpista", vectorCopia);
	    }
        else //mision Acabada
        {
        	SQLiteDatabase myDB = null;
        	myDB = this.openOrCreateDatabase("BDTesoros.s3db", 1, null);
            myDB.execSQL("UPDATE MISIONES set estado='completa' where _id='"+vector[1]+"'");
        	Toast.makeText(this, "  Mision Finaliza  ", Toast.LENGTH_LONG).show();
        	i = new Intent(this, SelMisionActivity.class);   
        	myDB.close();
        }
    }

	public void onClick(View v) {
		switch (v.getId()) {
    	case R.id.button_continue:    		
    		startActivity(i);
    		break;		
		}
	}

}
